package fatworm.parser.syntree;
/**
 * syntax query node
 * represent update command 
 */
public class UpdateTableNode extends QueryNode{
	public String tableName;
	public java.util.LinkedList<SetNode> setList;
	public WhereNode where;
	public UpdateTableNode( String tableName , 
			java.util.LinkedList<SetNode> setList ,WhereNode where ){
		this.tableName = tableName;
		this.setList = setList;
		this.where = where;
	}
	
	public String toString(){
		String ans = "UPDATE "+tableName +" SET ";
		for( java.util.Iterator<SetNode> i = setList.iterator(); i.hasNext();){
			ans += i.next();
			if( i.hasNext() ) ans += ",";
		}
		return ans + " WHERE "+ where;
	}
	
	public void accept( IQueryVisitor visitor ){
		visitor.visit( this );
	}
	/**
	 * syntax node 
	 * represent set expression in update 
	 * field_name = value
	 */
	public static class SetNode extends SyntaxNode{
		public String fieldName;
		public ValueNode value;
		public SetNode( String fieldName , ValueNode value ){
			this.fieldName = fieldName; this.value = value; 
		}
		public String toString(){
			return fieldName+"="+value;
		}
	}

}
